/*
 * Licensed under the License, Version 1.0 (the "License");
 * You may obtain a copy of the License at
 *   http://www.heavenick.com/license/License 
 * Copyright information Heavenick to all.
 * Unless the applicable legal requirements or written 
 * consent, can use or around the code, and no warranties 
 * of any kind and state responsibility.
 */
package com.heavenick.core.type;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

/**
 *
 *@author Heavenick
 *@version 1.0
 *@date 2012-8-5 下午1:11:46
 */
public class DateTypeHandler implements TypeHandler<Date> {

	public Date getResult(ResultSet arg0, String arg1) throws SQLException {
		java.sql.Date sqlDate = arg0.getDate(arg1);
		return new Date(sqlDate.getTime());
	}

	public Date getResult(ResultSet arg0, int arg1) throws SQLException {
		java.sql.Date sqlDate = arg0.getDate(arg1);
		return new Date(sqlDate.getTime());
	}

	public Date getResult(CallableStatement arg0, int arg1)
			throws SQLException {
		java.sql.Date sqlDate = arg0.getDate(arg1);
		return new Date(sqlDate.getTime());
	}

	public void setParameter(PreparedStatement arg0, int arg1, Date arg2,
			JdbcType arg3) throws SQLException {
		arg0.setDate(arg1, new java.sql.Date(arg2.getTime()));
	}

}
